package com.chen.springboot.controller;

import com.chen.springboot.common.AuthAccess;
import com.chen.springboot.common.Result;
import com.chen.springboot.entity.ItemParams;
import com.chen.springboot.service.ItemParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/itemParams")
public class ItemParamsController {
    
    @Autowired
    private ItemParamsService itemParamsService;
    
    /**
     * 根据商品ID获取参数信息
     */
    @AuthAccess
    @GetMapping("/getByItemId")
    public Result getByItemId(@RequestParam Long itemId) {
        ItemParams params = itemParamsService.getByItemId(itemId);
        return Result.success(params);
    }
    
    /**
     * 获取所有不重复的热门系列（分类）
     */
    @AuthAccess
    @GetMapping("/getHotSeriesList")
    public Result getHotSeriesList() {
        List<String> hotSeriesList = itemParamsService.getDistinctHotSeries();
        return Result.success(hotSeriesList);
    }
    
    /**
     * 保存或更新商品参数
     */
    @PostMapping("/save")
    public Result save(@RequestBody ItemParams itemParams) {
        itemParamsService.saveOrUpdate(itemParams);
        return Result.success();
    }
    
    /**
     * 删除商品参数
     */
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        itemParamsService.removeById(id);
        return Result.success();
    }
}

